<template>
	<div class="body Abnormal">
		<header>
			<i class="iconfont icon-xiangzuo1" @click="goPrev"></i
			><span>ZD/E补码</span
			><i class="iconfont icon-shanguangdeng" @click="flashOpenOrClose"></i
			><i class="iconfont closeScan" @click="closeScan">关闭</i>
		</header>
		<div class="common-box">
            <div class="content-box">
                <v-scan
                @scanData="scanData"
                ref="ch"
                :switchScan="switchScan"
                :loadingData="loadingData"
                ></v-scan>
            </div>
		</div>
		<div class="order-list">
			<p style="font-size: 16px">当前打印机： {{printerName}}</P>
		</div>
		<div class="footer-btn" @click="reconnectLanYa">重新连接</div>
		<!-- <div class="footer-btn" @click="confirmEnter">确认</div> -->
	</div>
</template>
<script>
  import Scan from '@/components/ContinuousScan';
  import Header from '@/components/header'
	import * as fetchObj from '@/api/index/reportAbnormal'
	import $ from "jquery"
	import { iatRecorder } from '@/utils/iatRecorder'
	import Vue from 'vue';
	import { Toast, Dialog } from 'vant';
	Vue.use(Toast).use(Dialog);
	export default {
		name: 'ReportAbnormal',
		components: {
			'v-scan': Scan,
      'v-header': Header,
		},
		data() {
			return {
				omsNo: '',
				loc: '',
				labelNo: '',
				ydq: '',
				orderQty: 1,
				loadingData: false,
				fetchObj,
				switchScan: true,
				printerName: ''
			}
		},
		watch: {
		},
		mounted() {
			// this.onPlusReady('e') // 获取APP经纬度
			// try {
			// 	CallAndroidOrIOS.ContinuousScan();
			// } catch (error) {}
		},
		created() {
      		window.LanYaMac2 = this.LanYaMac2;
			let obj = {
				...JSON.parse(localStorage.getItem('orderMac')),
				type: 'order'
			}
			if (localStorage.getItem('orderMac')) {
				this.printerName = JSON.parse(localStorage.getItem('orderMac')).name
			}
			setTimeout(() => {
				CallAndroidOrIOS.ReconnectLanYa(JSON.stringify(obj));
			}, 500)
		},
		methods: {
			reconnectLanYa () {
				let obj = {
					type: 'order',
					mac: '',
				}
				CallAndroidOrIOS.ReconnectLanYa(JSON.stringify(obj));
			},
			LanYaMac2(name, mac) {
				let obj = {
					name,
					mac
				}
				this.printerName = name
				localStorage.setItem('orderMac', JSON.stringify(obj));
			},
			// 扫描后
			scanData(data) {
				if (data.length < 11) {
					this.$alert('子单不能小于11位数,请重新扫描', '提示', {
						confirmButtonText: '确定'
					})
					return
				}
				let slice = data.slice(0,2);
				console.log(slice);
				if(slice == '25' || slice == '24' || slice == 'SF' ){
					let that = this;
					let postData = {
						code: data // 单号
					};
					that.omsNo = ''
					that.labelNo = data; // 订单号
					that.printOrder(); //只打印单号

				}else{
					this.$alert('单号有误', '提示', {
						confirmButtonText: '确定'
					})
					return
				}

			},
			printOrder() {
				let params = {
					labelNo: this.labelNo || "", // 单号
					omsNo: this.omsNo || "",
					way: 1
				}
				// this.$alert('开始打印'+this.labelNo, '提示', {
				// 	confirmButtonText: '确定'
				// })
				CallAndroidOrIOS.printOrder(JSON.stringify(params));
			},
			// 关闭扫描框
			closeScan() {
			// 安卓
			try {
				CallAndroidOrIOS.CancelScan();
			} catch (error) {}
			// 苹果
			try {
				window.webkit.messageHandlers.messageSend.postMessage({
				a: "离开app原生半屏扫描二维码/条码",
				});
			} catch (error) {}
			},
			//打开或关闭 闪光灯
			flashOpenOrClose() {
			let that = this;
			// 安卓
			try {
				if (that.ifflash) {
				CallAndroidOrIOS.setTorchEnabled_false(); // setTorchEnabled_false  闪光灯 关闭
				that.ifflash = false;
				} else {
				CallAndroidOrIOS.setTorchEnabled_true(); // setTorchEnabled_true  闪光灯 打开
				that.ifflash = true;
				}
			} catch (error) {}
			// 苹果
			try {
				window.webkit.messageHandlers.messageSend.postMessage({
				a: '打开或关闭闪光灯',
				});
			} catch (error) {}
			},
			// 关闭扫码框
			CloseScanBox() {
			// 安卓
			try {
				CallAndroidOrIOS.CancelScan();
			} catch (error) {}
			// 苹果
			try {
				window.webkit.messageHandlers.messageSend.postMessage({
				a: '离开app原生半屏扫描二维码/条码',
				});
			} catch (error) {}
			},
			goPrev() {
				this.closeScan()
				this.$router.go(-1);
			},
			switchScanFun(data) {
				if (data) {
				this.switchScan = true // 打开摄像头
				} else {
				this.switchScan = false // 关闭摄像头
				}
			},
			uploadOnChange(file) {
				this.switchScanFun(true); // 打开摄像头
			}
    	},
  		beforeDestroy () {
			this.closeScan()
  		}
  }
</script>
<style scoped lang="less">
	// @import "../../components/publicLess.less";
	.common-box {
		height: 100%;
	}
	.Abnormal {
		font-size: 28/50rem;
		.el-dialog {
			z-index: 9999;

		}
		/deep/ .el-dialog__header {
			padding: 0;
		}
		/deep/ .el-dialog__headerbtn {
			top: 2px;
			right: 5px;
		}
		/deep/ .el-dialog__body {
			padding: 20px 10px;
		}
	}
	.address {
		margin: 10/50rem;
		font-size: 32/50rem;
	}
	.tab {
		display: flex;
		margin-top: 20px;
		font-size: 20px;
		div {
			width: 50%;
			line-height: 26/50rem;
			padding-bottom: 10px;
			text-align: center;
			border-bottom: 2px solid #e1e1e1;
		}
		.active {
			color: #038EEA;
			border-color: #038EEA;
		}
	}
	.scan-label {
		.scan-label-item {
			margin: 10/50rem;
			border: 1px solid #e1e1e1;
			padding: 20/50rem 10/50rem;
			color: #9B9B9B;
			font-size: 32/50rem;
			.time-person {
				display: flex;
				justify-content: space-between;
				margin-bottom: 10/50rem;
			}
			.selectAddress {
				margin-bottom: 10/50rem;
			}
			span {
				color: #000;
			}
		}
	}
	.abnormal-list {
		.abnormal-list-item {
			margin: 10/50rem;
			border: 1px solid #e1e1e1;
			padding: 20/50rem 10/50rem;
			color: #9B9B9B;
			font-size: 32/50rem;
			.time-person {
				display: flex;
				justify-content: space-between;
				margin-bottom: 10/50rem;
			}
			span {
				color: #000;
			}
			.time-person2 {
				display: flex;
				margin-bottom: 10/50rem;
				.left {
					width: 260/50rem;
				}
			}
		}

	}
	.order-list {
		margin: 10px;
		div {
			font-size: 22px;
			span {
				color: #6f7180;
			}
		}
		.no-data {
			text-align: center;
			margin-top: 80px;
			color: #6f7180;
		}
	}
	.footer-btn {
		font-size: 22px;
		position: fixed;
		bottom: 20px;
		height: 50px;
		line-height: 50px;
		text-align: center;
		border-radius: 5px;
		width: 80%;
		background-color: #038EEA;
		color: #fff;
		margin-left: 10%;
	}
</style>
